package httpMsg;

import httpMsg.model.reInfo.HJFQuanInfo;
import httpMsg.model.reInfo.HJFReInfo;
import httpMsg.model.reInfo.HJFRetObjInfo;
import httpMsg.model.send.HJFClientReg;
import httpMsg.model.send.HJFFindQAJF;
import httpMsg.model.send.HJFPayQAJF;
import httpMsg.model.send.HJFQAInfo;
import httpMsg.model.send.HJFQuanType;
import httpMsg.model.send.HJFQueryClientQuan;
import httpMsg.model.send.HJFSendQA;
import httpMsg.model.send.HJFShopReg;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import com.alibaba.fastjson.JSON;

public class test {
	
	public static String STR_URL = null;
	public static String HTTPJSONINFO = null;
	public static String ACTION = null;
	
	public static void main(String[] args) {
//		C端会员注册
		test.register();
// 		会员券列表--分页显示
//		test.queryPagination();
//		积分购买券
//		test.jfoff();
//		发券
//		test.createByBuy();
//		C端用户积分和券查询接口
//		test.qandjf();
//		券和积分综合支付接口
//		test.quanjfoff();
//		批次号查询券积分现金
//		test.qandjfbybatchNo();
		
//		商户注册
//		test.shopRegister();
//		创建券类型
//		test.createws();
//		设置券状态
//		撤销接口
//		test.quanjfbackoff();
		System.out.println(new Date());
		
		HJFClient req = new HJFClient();
		HashMap<String, Object> map = req.HJFHttpJsonPost(STR_URL, ACTION, HTTPJSONINFO);
		if(map!=null && !map.isEmpty()){
			test.showCallBack(map);
		}
    }
	
	/**
	 * 
	 * @param map
	 */
	public static void showCallBack(HashMap<String, Object> map){
		if(map.containsKey("ErrCode")){
			System.out.println("http请求错误："+map.get("ErrCode"));
		} else {
			HJFReInfo reMsg = (HJFReInfo)map.get("reMsg");
			if(reMsg==null)
				return ;
			System.out.println("----------------------------------------------------");
			System.out.println("Jf:"+reMsg.getJf());
			System.out.println("Payjf:"+reMsg.getPayjf());
			System.out.println("RetCode:"+reMsg.getRetCode());
			System.out.println("RetMsg:"+reMsg.getRetMsg());
			System.out.println("ShopId:"+reMsg.getShopId());
			System.out.println("TobepaytrsAmt:"+reMsg.getTobepaytrsAmt());
			System.out.println("TransTime:"+reMsg.getTransTime());
			System.out.println("UserId:"+reMsg.getUserId());
			System.out.println("batchNo:"+reMsg.getBatchNo());
			System.out.println("amt:"+reMsg.getAmt());
			System.out.println("Ql.size:"+(reMsg.getQl()==null?0:reMsg.getQl().size()));
			
			if(reMsg.getQl()!=null && reMsg.getQl().size()>0){
				int flag1 = 0;
				for(HJFQAInfo qaninfo: reMsg.getQl()){
					System.out.println();
					System.out.println("*****Ql."+flag1+"*****");
					flag1++;
					
					System.out.println("quancode:"+qaninfo.getQuancode());
					System.out.println("quanprice:"+qaninfo.getQuanprice());
					System.out.println("quanname:"+qaninfo.getQuanname());
					System.out.println("quanTypeName:"+qaninfo.getQuanTypeName());
				}
			}

			HJFRetObjInfo retObj = reMsg.getRetObj();
			if(retObj!=null){
				System.out.println();
				System.out.println("*****HJFRetObjInfo*****");
				System.out.println("checkPassLastPageNo:"+retObj.isCheckPassLastPageNo());
				System.out.println("firstPage:"+retObj.isFirstPage());
				System.out.println("firstResult:"+retObj.getFirstResult());
				System.out.println("lastPage:"+retObj.isLastPage());
				System.out.println("nextPage:"+retObj.getNextPage());
				System.out.println("pageNo:"+retObj.getPageNo());
				System.out.println("pageSize:"+retObj.getPageSize());
				System.out.println("pretPage:"+retObj.getPretPage());
				System.out.println("selectTotalCount:"+retObj.isSelectTotalCount());
				System.out.println("startIndex:"+retObj.getStartIndex());
				System.out.println("totalCount:"+retObj.getTotalCount());
				System.out.println("totalPage:"+retObj.getTotalPage());
				
				System.out.println();
				System.out.println("*****HJFRetObjInfo.condition*****");
				System.out.println("condition.channel:"+retObj.getCondition().getChannel());
				System.out.println("condition.numPerPage:"+retObj.getCondition().getNumPerPage());
				System.out.println("condition.online:"+retObj.getCondition().isOnline());
				System.out.println("condition.pageNum:"+retObj.getCondition().getPageNum());
				System.out.println("condition.userId:"+retObj.getCondition().getUserId());
				
				ArrayList<HJFQuanInfo> list = retObj.getList();
				if(list!=null && list.size()>0){				
					int flag = 0;
					for(HJFQuanInfo quaninfo: list){
						System.out.println();
						System.out.println("*****HJFRetObjInfo.list."+flag+"*****");
						flag++;
						
						System.out.println("batchNo:"+quaninfo.getBatchNo());
						System.out.println("cancelDate:"+test.formatDate(quaninfo.getCancelDate()));
						System.out.println("createDate:"+test.formatDate(quaninfo.getCreateDate()));
						System.out.println("createShop:"+quaninfo.getCreateShop());
						System.out.println("createShopName:"+quaninfo.getCreateShopName());
						System.out.println("expireDate:"+test.formatDate(quaninfo.getExpireDate()));
						System.out.println("id:"+quaninfo.getId());
						System.out.println("ownerShopName:"+quaninfo.getOwnerShopName());
						System.out.println("remark:"+quaninfo.getRemark());
						System.out.println("sendRule:"+quaninfo.getSendRule());
						System.out.println("settled:"+quaninfo.isSettled());
						System.out.println("status:"+quaninfo.getStatus());
						System.out.println("userId:"+quaninfo.getUserId());
						System.out.println("userPhone:"+quaninfo.getUserPhone());
						System.out.println("validDate:"+test.formatDate(quaninfo.getValidDate()));
						
						System.out.println("*****HJFRetObjInfo.list.quanType*****");
						System.out.println("buyPriceCash:"+quaninfo.getQuanType().getBuyPriceCash());
						System.out.println("buyPriceJf:"+quaninfo.getQuanType().getBuyPriceJf());
						System.out.println("createDate:"+test.formatDate(quaninfo.getQuanType().getCreateDate()));
						System.out.println("getWay:"+quaninfo.getQuanType().getBuyWay());
						System.out.println("id:"+quaninfo.getQuanType().getId());
						System.out.println("kind:"+quaninfo.getQuanType().getKind());
						System.out.println("name:"+quaninfo.getQuanType().getName());
						System.out.println("needSettle:"+quaninfo.getQuanType().isNeedSettle());
						System.out.println("ownerShop:"+quaninfo.getQuanType().getOwnerShop());
						System.out.println("ownerShopIncludeSub:"+quaninfo.getQuanType().isOwnerShopIncludeSub());
						System.out.println("planAmount:"+quaninfo.getQuanType().getPlanAmount());
						System.out.println("price:"+quaninfo.getQuanType().getPrice());
						System.out.println("randCode:"+quaninfo.getQuanType().getRandCode());
						System.out.println("realAmount:"+quaninfo.getQuanType().getRealAmount());
						System.out.println("settlePrice:"+quaninfo.getQuanType().getSettlePrice());
						System.out.println("status:"+quaninfo.getQuanType().isStatus());
						System.out.println("union:"+quaninfo.getQuanType().isUnion());
						System.out.println("used:"+quaninfo.getQuanType().isUsed());
						System.out.println("validDays:"+quaninfo.getQuanType().getValidDays());
					}
				}
			}
			System.out.println("----------------------------------------------------");
		}
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/jfwebservice1/register?
     * data= {"loginName":"test00004","password":"123456","payPassword":"123456",
     * ,"idCradNo":"1","name":"1","inviterShop":"1","registerWay":"pc"}
	 */
	public static void register() {
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfwebservice1/register";
		HJFClientReg clientreg = new HJFClientReg();
		clientreg.setLoginName("13308900221");  
		clientreg.setPassword("123456");
		clientreg.setPayPassword("123456");
		clientreg.setIdCardNo("331305199007112524");
		clientreg.setName("1");
		clientreg.setInviterShop("1s"); 
		clientreg.setRegisterWay("pc");
		HTTPJSONINFO = JSON.toJSONString(clientreg);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/jfShopService/shopRegister?
	 * data={shopName":"1","pwd":"1","shopType":"1","mobile":"1","name":"123",
	 * "assistantId":"123456","registerWay":"pc"}
	 */
	public static void shopRegister(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfShopService/shopRegister";
		HJFShopReg shopreg = new HJFShopReg();
		shopreg.setShopName("shop00001");
		shopreg.setPwd("123456");
		shopreg.setShopType("1");
		shopreg.setMobile("13308901211");
		shopreg.setName("1234455");
		shopreg.setAssistantId("test023002");
		shopreg.setRegisterWay("pc");
		HTTPJSONINFO = JSON.toJSONString(shopreg);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/jfwebservice1/qandjf?
	 * data= {"userId":"508613998bb94ee898c35cf131ced041","shopId":"097ab306a2154dd795adc0764bb9c0e4",
	 * "registerWay":"pc"}
	 */
	public static void qandjf(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfwebservice1/qandjf";
		HJFFindQAJF qajf = new HJFFindQAJF();
		qajf.setUserId("8c0ad7648daa47e9bfa7b178b5d182ac");
		qajf.setShopId("3b5883a429c64b18ab72a3b8988e5938");
		qajf.setRegisterWay("pc");
		HTTPJSONINFO = JSON.toJSONString(qajf);
	}
	
	/** 
	 * http://192.168.230.110:8087/hjf-admin/jfwebservice/quanjfoff?
	 * data={"batchNo":"aaaaaaa","jfFlag":"true","paypassword":"123456",
	 * "ql":[{"quancode":"495610687727"}{"quancode":"495600765504"}],
	 * "shopId":"c4bd461f36224676acc340c4ef2f0b59","trsAmt":"10000",
	 * "userId":"e3f2c3bee88249d0abe3643596d606f1"}
	 */
	public static void quanjfoff(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfwebservice/quanjfoff";
		HJFPayQAJF<HJFQAInfo> clientpay = new HJFPayQAJF<HJFQAInfo>();
		
		ArrayList<HJFQAInfo> arrQA = new ArrayList<HJFQAInfo>();
		HJFQAInfo q0 = new HJFQAInfo();
		q0.setQuancode("495600765504");
		arrQA.add(q0);
		HJFQAInfo q1 = new HJFQAInfo();
		q1.setQuancode("495610687727");
		arrQA.add(q1);
		
		clientpay.setBatchNo("aaaaaaa");
		clientpay.setJfFlag("true");
		clientpay.setPaypassword("123456");
		clientpay.setQl(arrQA);
		clientpay.setShopId("c4bd461f36224676acc340c4ef2f0b59");
		clientpay.setTrsAmt(10000);
		clientpay.setUserId("e3f2c3bee88249d0abe3643596d606f1");
		HTTPJSONINFO = JSON.toJSONString(clientpay);		
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/springws2?
	 * trade=IQuanTypeService.createws&
	 * data={"buyPriceCash":"150","buyPriceJf":"55","planAmount":"5",
	 * "buyWay":"byJfCash","getWay":"buy","kind":"cash","price":"111",
	 * "validDays":"7","status":"ok"} 
	 */
	public static void createws(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/springws2";
		ACTION = "IQuanTypeService.createws";
		HJFQuanType quanType = new HJFQuanType();
		quanType.setName("ceshiquan_0001");
		quanType.setPrice(111);
		quanType.setBuyPriceCash(150);
		quanType.setBuyPriceJf(55);
		quanType.setPlanAmount(5);
		quanType.setValidDays(7);
		quanType.setBuyWay("byJfCash");
		quanType.setGetWay("buy");
		quanType.setKind("cash");
		quanType.setStatus(false);
		quanType.setShopId("3b5883a429c64b18ab72a3b8988e5938");
		quanType.setUserId("e3f2c3bee88249d0abe3643596d606f1");
		HTTPJSONINFO = JSON.toJSONString(quanType);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/springws2?
	 * trade=IQuanTypeService.setStatus&
	 * data={"id":"09d8ebb7654543bead84e67d5fc29156",
	 * "status":true,"loginShop":"76a787f4571e4a01baa497be0dce2a99"} 
	 */
	public static void setStatus(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/springws2";
		ACTION = "IQuanTypeService.setStatus";
		HJFQuanType quanType = new HJFQuanType();
		quanType.setId("09d8ebb7654543bead84e67d5fc29156");
		quanType.setStatus(true);
		quanType.setLoginShop("76a787f4571e4a01baa497be0dce2a99");
		HTTPJSONINFO = JSON.toJSONString(quanType);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/springws2?
	 * trade=IQuanService.createByBuy&
	 * data={"quanTypeId":"09d8ebb7654543bead84e67d5fc29156",
	 * "userId":"221dbea5335e4991a73749281518798b","buyWay":"byJf",
	 * "buyAmount":"10"}
	 */
	public static void createByBuy(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/springws2";
		ACTION = "IQuanService.createByBuy";
		HJFSendQA sendQA = new HJFSendQA();
		sendQA.setBatchNo("1234567890");
		sendQA.setQuanTypeId("09d8ebb7654543bead84e67d5fc29156");
		sendQA.setUserId("221dbea5335e4991a73749281518798b");
		sendQA.setBuyWay("byJf");
		sendQA.setBuyAmount(10);
		HTTPJSONINFO = JSON.toJSONString(sendQA);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/jfwebservice/quanjfbackoff?
	 * &data={"batchNo":"a","userId":"5afe5665629445549083fd1bc59927c0"}
	 */
	public static void quanjfbackoff(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfwebservice/quanjfbackoff";
		HJFPayQAJF<Object> backOffQuanJF = new HJFPayQAJF<Object>();
		backOffQuanJF.setBatchNo("a");
		backOffQuanJF.setUserId("5afe5665629445549083fd1bc59927c0");
		HTTPJSONINFO = JSON.toJSONString(backOffQuanJF);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/springws2?
	 * trade=IQuanService.queryPagination&
	 * data={"quanCondition":{"userId":"60845918ace84bde80bd5bef5d390cfe"},
	 * "pageNo":"1","pageSize":"5","status":"1",
	 * "createDateStart":"1","createDateEnd":"2"}
	 */
	public static void queryPagination(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/springws2";
		ACTION = "IQuanService.queryPagination";
		
		HJFSendQA qa = new HJFSendQA();
		qa.setUserId("c405fc07a9194490b622d31f6d00349f");
		
		HJFQueryClientQuan<HJFSendQA> queryClientQuan = new HJFQueryClientQuan<HJFSendQA>();
		queryClientQuan.setQuanCondition(qa);
		queryClientQuan.setPageNo(1);
		queryClientQuan.setPageSize(5);
		queryClientQuan.setStatus(0);
		queryClientQuan.setCreateDateStart(new Date());
		queryClientQuan.setCreateDateEnd(new Date());
		
		HTTPJSONINFO = JSON.toJSONString(queryClientQuan);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/jfwebservice/jfoff?
	 * data={"batchNo":"1234567","userId":"60845918ace84bde80bd5bef5d390cfe",
	 * "payPassword":"123456","quanTypeId":"a65c22d192d74cc686347b90eaf75844"}
	 */
	public static void jfoff(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfwebservice/jfoff";
		HJFPayQAJF payQAJF = new HJFPayQAJF();
		payQAJF.setBatchNo("1234567");
		payQAJF.setUserId("60845918ace84bde80bd5bef5d390cfe");
		payQAJF.setPaypassword("123456");
		payQAJF.setQuanTypeId("a65c22d192d74cc686347b90eaf75844");
		HTTPJSONINFO = JSON.toJSONString(payQAJF);
	}
	
	/**
	 * http://192.168.230.110:8087/hjf-admin/jfwebservice1/qandjfbybatchNo?
	 * data={"batchNo":"456789","userId":"60845918ace84bde80bd5bef5d390cfe"}
	 */
	public static void qandjfbybatchNo(){
		STR_URL = "http://192.168.230.110:8087/hjf-admin/jfwebservice1/qandjfbybatchNo";
		HJFSendQA sendQA = new HJFSendQA();
		sendQA.setBatchNo("456789");
		sendQA.setUserId("60845918ace84bde80bd5bef5d390cfe");
		HTTPJSONINFO = JSON.toJSONString(sendQA);
	}
	
	
	/**
	 * 日期格式化
	 * @param date
	 * @return
	 */
	public static String formatDate(Date date){
		if(date!=null){
			java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			return format1.format(date);
		} else {
			return "";
		}
	}
}
